package asia.lxq.cic.controller;

import asia.lxq.cic.entity.Result;
import asia.lxq.cic.entity.User;
import asia.lxq.cic.service.AdminService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.security.core.Authentication;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/admin")
//@PreAuthorize("hasAnyAuthority('分站管理员','总站管理员')")
public class AdminController {

    @Autowired
    AdminService adminService;

    @GetMapping("/user_list")
    public Result<Object> userList(@RequestParam(required = false,defaultValue = "1") int page,
                                   @RequestParam(required = false,defaultValue = "100") int pageSize){
        return adminService.userList(page, pageSize);
    }

    @PostMapping("/user/add_user")
    public Result<Object> addUser(@RequestBody List<User> userList){
        return adminService.addUser(userList);
    }

    @PostMapping("/user/del_user")
    public Result<Object> deleteUserList(@RequestBody int[] userIds){
        return adminService.deleteUserList(userIds);
    }

    @PostMapping("/user/update_user")
    public Result<Object> updateUser(@RequestBody User user, Authentication authentication){
        return adminService.updateUser(user,authentication);
    }
}
